package com.jingbian.cppccbackend.mapper.admin;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jingbian.cppccbackend.entity.PublicOpinionAttachments;
import com.jingbian.cppccbackend.entity.PublicOpinions;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 社情民意信息表 Mapper 接口
 * </p>
 *
 * @author yezi
 * @since 2025-04-26
 */
@Mapper
public interface adminPublicOpinionsMapper extends BaseMapper<PublicOpinions> {

    /**
     * 查询某个社情民意的详情
     */
    PublicOpinions getPublicOpinionById(@Param("opinionId") Integer opinionId);

    /**
     * 搜索框搜索
     */
    List<PublicOpinions> searchPublicOpinions(@Param("searchText") String searchText);

    /**
     * 查询所有社情民意数据
     */
    List<PublicOpinions> getAllPublicOpinionsWithDetails(String status, String opinionType, String startDate, 
            String endDate, String sort, String department, String searchText, Integer pageStatus);

    /**
     * 修改社情民意状态
     */
    void updatePublicOpinionStatus(Integer opinionId, String status, Boolean isOr, Integer pageStatus, 
            String department, String handing_result);

    /**
     * 退回
     */
    void sendBack(Integer opinionId, String status, Boolean isOr, Integer pageStatus, String department);

    /**
     * 公示
     */
    void publicity(Integer opinionId, String status, Boolean isOr);

    /**
     * 获取社情民意总数
     */
    @Select("SELECT COUNT(*) FROM public_opinions")
    Integer getTotalPublicOpinions();

    /**
     * 获取昨日新增社情民意数
     */
    @Select("SELECT COUNT(*) FROM public_opinions WHERE DATE(submit_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)")
    Integer getNewPublicOpinionsYesterday();

    /**
     * 获取已完结社情民意数
     */
    @Select("SELECT COUNT(*) FROM public_opinions WHERE status = '处理完结'")
    Integer getCompletedPublicOpinions();

    /**
     * 获取社情民意类型分布
     */
    List<Map<String, Object>> getPublicOpinionTypeDistribution();

    /**
     * 获取社情民意提交趋势
     */
    List<Map<String, Object>> getPublicOpinionTrend(String startDate, String endDate);

    /**
     * 插入处理附件
     */
    void insertHandlingAttachment(PublicOpinionAttachments attachment);
}
